<?php
$GLOBALS['PAGE_FORM_DATA'] = array();
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
$dt = new DataTable(constant('DB_TABLE_WORKING'));
$GLOBALS['GV_IMAGE_PATH'] = 'working/';
$dt_image =  new DataTable(constant('DB_TABLE_ARTICLE_IMAGE'));
if ( $act == 'save') {
	$working_data = $_REQUEST;
	if ( strlen($working_data['ajaxf_image']) > 0) {
		$GLOBALS['APP_INSTANCE']->saveUploadedFile($working_data['ajaxf_image'], $GLOBALS['GV_IMAGE_PATH'] );
		$working_data['img_path'] = $working_data['ajaxf_image'];
	}
	if ( isset($working_data['meta_keyword']) AND is_array($working_data['meta_keyword']) ) {
		$working_data['meta_keyword'] = implode(',', $working_data['meta_keyword'] );
	}else{
		$working_data['meta_keyword'] = '';
	}
	$dt->save($working_data);
	
	ob_clean();
	$redirect_url = 'working.php';
	$redirect_url .= '?sub_cat_id='.$working_data['cat_id'];
	header('Location:'.$redirect_url);
	exit();
}
else if ( $act == 'edit') {
	$GLOBALS['PAGE_FORM_DATA'] = $dt->get(intval($_REQUEST['id']));
	$GLOBALS['PAGE_FORM_DATA']['meta_keyword'] = explode(',', $GLOBALS['PAGE_FORM_DATA']['meta_keyword'] );
}
else{
	$GLOBALS['PAGE_FORM_DATA'] = $_REQUEST;
	$GLOBALS['PAGE_FORM_DATA']['id'] = 0;
	if ( !isset($GLOBALS['PAGE_FORM_DATA']['cat_id']) )
		$GLOBALS['PAGE_FORM_DATA']['cat_id'] = 0;

	$GLOBALS['PAGE_FORM_DATA']['title'] = '';
	$GLOBALS['PAGE_FORM_DATA']['content'] = '';
	$GLOBALS['PAGE_FORM_DATA']['date'] = $GLOBALS['APP_INSTANCE']->formatDate();
	$GLOBALS['PAGE_FORM_DATA']['image_path'] = false;
	$GLOBALS['PAGE_FORM_DATA']['meta_keyword'] = array();
	$GLOBALS['PAGE_FORM_DATA']['meta_description'] = '';

}
?>